package com.lancoo.lancooimageloader.glide;

import android.content.Context;

import com.bumptech.glide.request.RequestOptions;
import com.lancoo.lancooimageloader.LancooImageLoader;
import com.lancoo.lancooimageloader.LancooImageOptions;
import com.lancoo.lancooimageloader.OptionConverter;

/**
 * Created by gongwq on 2017/6/12 0012.
 */

public class GlideOptionConverter extends OptionConverter<RequestOptions> {
    private RequestOptions mRequsetOptions;
    private Context mContext;
    public GlideOptionConverter(LancooImageOptions mImageOptions) {
        super(mImageOptions);
        mContext= LancooImageLoader.getContex();
    }

    @Override
    public RequestOptions getImageOptions() {
        LancooImageOptions lancooImageOptions=getLancooImageOptions();
        if (mRequsetOptions == null) {
            mRequsetOptions=new RequestOptions()
                .override(lancooImageOptions.getWidth(),lancooImageOptions.getHeight())
                .error(lancooImageOptions.getFailureDrawable())
                .error(lancooImageOptions.getFailureDrawableId())
                .placeholder(lancooImageOptions.getLoadingDrawableId())
                .placeholder(lancooImageOptions.getLoadingDrawable())
                .skipMemoryCache(lancooImageOptions.isUseMemCache());


            switch (lancooImageOptions.getImageScaleType()){
                case CENTER:
                    break;
                case CENTER_CROP:
                    mRequsetOptions.optionalCenterCrop();
                  //  Log.e("Glide--->","centerCrop");
                    break;
                case CENTER_INSIDE:
                    mRequsetOptions.optionalCenterInside();
                    break;
                case FIT_CENTER:
                    mRequsetOptions.optionalFitCenter();
                    break;
                case FIT_END:
                    break;
                case FIT_START:
                    break;
                case FIT_XY:
                    break;
                case MATRIX:
                    break;

            }
            if (lancooImageOptions.isCircular()){
                //Log.e("---->","圆形图片裁剪");
                mRequsetOptions.transform(new GlideCircleTransform(mContext));
            }
        }
        return mRequsetOptions;
    }
}
